<template>
  <div v-if="result">
    <list-title>{{ result.cat }}</list-title>
    <loading v-if="result.playlists.length == 0"></loading>
    <ul class="imglist" v-else>
      <router-link
        tag="li"
        v-for="index in result.playlists.length"
        :key="index"
        :to="`/playlist/${result.playlists[index - 1].id}`"
      >
        <div>
          <img :src="result.playlists[index - 1].coverImgUrl" />
          <span class="icon"
            ><i class="fa fa-headphones" aria-hidden="true"></i
            >{{ result.playlists[index - 1].playCount | formatNum(1) }}</span
          >
          <h5>{{ result.playlists[index - 1].name }}</h5>
        </div>
      </router-link>
    </ul>
  </div>
</template>
<script>
import ListTitle from "@/components/ListTitle";
import Loading from "@/components/Loading.vue";
export default {
  name: "Cat",
  props: {
    cat: [String, Number],
  },
  data() {
    return {
      result: null,
    };
  },
  components: {
    ListTitle,
    Loading,
  },
  beforeRouteEnter(to, from, next) {
    next((vm) => {
      vm.axios.get(`/top/playlist/catlist?cat=${vm.cat}`).then((result) => {
        vm.result = result;
      });
    });
  },
};
</script>
<style scoped lang="less">
.imglist {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-evenly;
  padding-bottom: 50px;
  li {
    width: 165px;
    height: 215px;
    position: relative;
    img {
      border-radius: 10px;
      width: 100%;
      display: block;
    }
    .icon {
      position: absolute;
      text-align: right;
      // bottom:25%;
      // left: 0px;
      top: 0;
      right: 0;
      border-radius: 30px;
      color: white;
      font-size: 12px;
      font-weight: 400;
      line-height: 14px;
      padding: 2px 5px 2px 22px;
      background-color: rgba(0, 0, 0, 0.5);
      i {
        position: absolute;
        line-height: 14px;
        left: 7px;
      }
    }
    h5 {
      line-height: 20px;
      -webkit-line-clamp: 2;
      overflow: hidden;
      display: -webkit-box;
      -webkit-box-orient: vertical;
    }
  }
}
</style>